//
//  BROderReportViewController.m
//  BrezzeSaaS
//
//  Created by IOS on 2021/10/8.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import "BROderReportViewController.h"
#import "BRFaultItemView.h"
#import "BRRefunedStatusViewController.h"
#import "BRScanViewController.h"

@interface BROderReportViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate,QMUITextViewDelegate,QMUITextFieldDelegate>
{
    UIView *_faultView;
    NSArray  *_faults;
    NSInteger _selectIndex;
    
    NSMutableArray *_imgArrs; //images
    UIStackView *_stackView;  //imageView
    QMUILabel *_imgNumL;
    NSMutableArray *_allSelectedArr;
    
    QMUITextView *_textView;
    QMUITextField *_numTextF;
    QMUILabel *_inPutNumL;
}

@property (nonatomic,strong) NSArray *faults;

// 是否单选
@property (nonatomic,assign) BOOL isSingle;

@end

@implementation BROderReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _imgArrs = [NSMutableArray array];
    _allSelectedArr = [NSMutableArray array];
    _selectIndex = -1; //单选默认无选择
    [self setUI];
}
#pragma mark - Request --
- (void)report {
    
    NSString *url = [BRAPI feedback];
       
    if (self.isSingle) {
        
        if (_selectIndex == -1) {
            
            NSLog(@"faq issu选择单选");
            [BRHud showAuto:Localized(@"toast_selOption") inView:self.view];
            return;
        }
        if (_numTextF.text.length == 0) {
            [BRHud show:Localized(@"toast_requiredEmail") inView:self.view];
            return;
        }
        if (![BRTools checkEmail:_numTextF.text]) {
            
            [BRHud showAuto:Localized(@"toast_validEmail")inView:self.view];
            return;
        }
       
        if (![self tipeShow]) return;
        
//        if (self.vcType == Report_Swap || self.vcType == Report_buyPB) {
//            // 提交置换\购买错误
//
//            [self requestSwapIssue];
//
//            return;
//        }
        
        [self requestFeedback:url];
        
    }else if (self.vcType == Report_faulty) {
        
        if (_allSelectedArr.count == 0) {
            
            NSLog(@"faq issu 多选==0");
            [BRHud showAuto:Localized(@"toast_selOption") inView:self.view];
            return;
        }
        if (_numTextF.text.length == 0) {
            
            [BRHud showAuto:Localized(@"toast_enterStationID") inView:self.view];
            return;
        }
        
        if (![self tipeShow]) return;
        url = [BRAPI reportDamage];
        [self requestDamage:url];
        
    }else {
        
        if (_numTextF.text.length == 0) {
            [BRHud showAuto:Localized(@"toast_enterStationID") inView:self.view];
            return;
        }
        if (![self tipeShow]) return;
        url = [BRAPI reportOrderProblem];
        [self requestReportProblem:url];
    }
    
}

- (BOOL)tipeShow {
    
    if (_textView.text.length == 0) {
        
        
        NSLog(@"请输入建议内容 ");
        [BRHud showAuto:Localized(@"help_inputFBContent") inView:self.view];
        return NO;
    }
    if (_imgArrs.count == 0) {
        if (self.vcType == Report_FAQ) return YES; //FAQb不限制图片必传
        [BRHud showAuto:Localized(@"toast_requiredPhoto") inView:self.view];
        return NO;
    }
    
    return YES;
}

/// SwapIssue
- (void)requestSwapIssue {
    NSString *imgs = @"";
    if (_imgArrs.count != 0) {
        imgs  = [_imgArrs componentsJoinedByString:@","];
    }
    [BRHud showInView:self.view];
    NSInteger type  = _selectIndex;
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:3];
    dic[@"content"] = _textView.text;
    dic[@"email"] = _numTextF.text;
    dic[@"refund"] = self.type >= 3 ? @1 : @0;
//    dic[@"scene"] = @(self.state == 1 ? 2 : 3);
    
    dic[@"type"] = @(type);
    dic[@"images"] = imgs;
    if (self.orderNo.length != 0) {
        dic[@"orderNo"] = self.orderNo;
    }
    
    NSString *url = [BRAPI feedbackSwap];
    [self request:url parma:dic];
}

/// Feedback
- (void)requestFeedback:(NSString *)url {
    NSString *imgs = @"";
    if (_imgArrs.count != 0) {
        imgs  = [_imgArrs componentsJoinedByString:@","];
    }
    [BRHud showInView:self.view];
    NSInteger type  = _selectIndex;
    
    NSDictionary *parms = @{
        @"content": _textView.text,
        @"email": _numTextF.text,
        @"images": imgs,
        @"type": @(type)
    };
    
    [self request:url parma:parms];
}

/// Report_faulty
- (void)requestDamage:(NSString *)url {
    NSString *imgs = @"";
    if (_imgArrs.count != 0) {
        imgs  = [_imgArrs componentsJoinedByString:@","];
    }
    [BRHud showInView:self.view];
    NSString *typeStr  = @"";
    if (_allSelectedArr.count != 0) {
        typeStr = [_allSelectedArr componentsJoinedByString:@","];
    }
    
    NSDictionary *parms = @{
        @"description": _textView.text,
        @"cabinetNo": _numTextF.text,
        @"images": imgs,
        @"damageType": typeStr,
        @"orderNo":self.orderNo
    };
    
    [self request:url parma:parms];
    
}

- (void)request:(NSString *)url parma:(NSDictionary *)parms {
    [[BRRequestManager shared] POST:url params:parms succeed:^(NSDictionary * _Nonnull dataDict, NSInteger respCode) {
        
        [BRHud hiddenInView:self.view];
        NSLog(@"feedback---%@",dataDict);
       
        if (self.vcType == Report_FAQ ) {

            [self pushSuccVC:1];
            
        }else {
            [self pushSuccVC:3];
        }
        
    } failed:^(NSInteger code, NSString * _Nonnull errMsg) {
        [BRHud hiddenInView:self.view];
    }];
}


/// 订单未1 充电宝不弹出 2 充电宝归还不结束
- (void)requestReportProblem:(NSString *)url {
    [BRHud showInView:self.view];
    
    NSString *imgs = @"";
    if (_imgArrs.count != 0) {
        imgs  = [_imgArrs componentsJoinedByString:@","];
    }
    
    NSDictionary *parms = @{
        @"description": _textView.text,
        @"cabinetNo": _numTextF.text,
        @"images": imgs,
        @"orderType": @(self.orderType),
        @"orderNo":self.orderNo
    };
    
    [[BRRequestManager shared] POST:url params:parms succeed:^(NSDictionary * _Nonnull dataDict, NSInteger respCode) {
        
        [BRHud hidden];
        NSLog(@"订单未1 充电宝不弹出 2 充电宝归还不结束---%@",dataDict);
        
        [self pushSuccVC:2];
        
    } failed:^(NSInteger code, NSString * _Nonnull errMsg) {
        [BRHud hidden];
    }];
    
}

- (void)pushSuccVC:(NSInteger)type {
    BRRefunedStatusViewController *vc = [[BRRefunedStatusViewController alloc] init];
    vc.typeIn = type;
    if (type == 1) vc.feedBackInd = self.feedbackIn;
//    vc.isHomeBack = (self.vcType == Report_Swap || self.vcType == Report_buyPB);
    vc.popType = self.popType;
    vc.maxAmount = self.maxAmount;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - Func --
- (NSArray *)faults {
    
    if (self.vcType == Report_FAQ || self.vcType == Report_Swap || self.vcType == Report_buyPB) {
        // feedback // 置换问题
        return @[Localized(@"help_funcIssues"),Localized(@"help_suggestion"),Localized(@"help_others2")];
    }
    
    // 订单问题
    return @[Localized(@"home_cableFaulty"),Localized(@"home_brokenTip"),Localized(@"home_canNotCharge"),Localized(@"home_indicatorError"),Localized(@"home_other")];
    
}

- (void)faultClick:(UITapGestureRecognizer *)tap {
    
    NSInteger tag  = tap.view.tag;
    
    
    if (self.isSingle) {
        
        NSInteger selInt  = tag -100;
        _selectIndex = selInt + 1;
        if (selInt == 2) {
            _selectIndex = 4;
        }
        //单选
        for (int i  = 0; i < self.faults.count; i++) {
            
            BRFaultItemView *itemView  = (BRFaultItemView *)[_faultView viewWithTag:i + 100];
            itemView.isSelected = (tag == i+100) ? YES : NO;
        }
    }else {
        //多选
        BRFaultItemView *itemView  = (BRFaultItemView *)tap.view;
        itemView.isSelected = !itemView.isSelected;
        
        NSInteger selInt  = tag -100 + 1;
        if (selInt == 5) selInt = 0;
        NSNumber *selNum  = [NSNumber numberWithInteger:selInt];
        if (itemView.isSelected) {
            
            if (![_allSelectedArr containsObject:selNum]) {
                [_allSelectedArr addObject:selNum];
            }
        }else {
            if ([_allSelectedArr containsObject:selNum]) {
                
                [_allSelectedArr removeObject:selNum];
            }
        }
        
    }
    
}

- (void)imgTouch:(QMUIButton *)btn {
    
    [self.view endEditing:YES];
    NSInteger index = btn.tag - 200;
    if (index != 3) {
        
//        BRCustiomAlertView *alertV = [[BRCustiomAlertView alloc] initWithTitle:@"Delete" subTitle:@"did you want to delete image?" cancelAction:^{
//            NSLog(@"取消");
//
//        } successAction:^{
//            NSLog(@"确定");
//
//
//        } showBC:YES];
//
//        [self.view addSubview:alertV];
        [self deleteImg:index];
      
    }else {
        
        [self showSelectPhoto];
        
    }
}

- (void)deleteImg:(NSInteger)index {
    
    if (index >= _imgArrs.count) return;
    NSString *file = _imgArrs[index];
    
    [[BRRequestManager shared] DELETE:[BRAPI filesDelete] params:@{@"file":file} succeed:^(NSDictionary * _Nonnull dataDict, NSInteger respCode) {
            
        } failed:^(NSInteger code, NSString * _Nonnull errMsg) {
            
        }];
    
    [_imgArrs removeObjectAtIndex:index];
    
    [self resetImagesView];
}

- (void)resetImagesView {
    
    QMUIButton *delBtn = (QMUIButton *)[_stackView viewWithTag:203];
    delBtn.hidden = _imgArrs.count >= 3;
    for (int i = 0; i < 3; i++) {
        
        QMUIButton *btn = (QMUIButton *)[_stackView viewWithTag:200 + i];
        
        if (i < _imgArrs.count) {
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",USERManager.filesSever,_imgArrs[i]]];
            [btn sd_setBackgroundImageWithURL:url forState:UIControlStateNormal];
            btn.accessibilityIdentifier = @"hasImg";
        }
        
        btn.hidden = i >= _imgArrs.count;
    }
    
    _imgNumL.text = [NSString stringWithFormat:@"%ld/3",_imgArrs.count];
}

- (void)openCameraClick:(QMUIButton *)btn {
    
    //打开相机获取机柜码
    BRScanViewController *scanleVC = [[BRScanViewController alloc] init];
    scanleVC.scanleStatus = SCANLE_DevNumber;
    [self.navigationController pushViewController:scanleVC animated:YES];
    
    scanleVC.blockScanNum = ^(NSString * _Nonnull numStr, NSString * _Nonnull urlStr) {
        self->_numTextF.text = numStr;
    };
   
    
}

- (void)submit {
    
    [self report];
    
    
    
}

- (void)showSelectPhoto {
    
    /**
     *  弹出提示框
     */
    //初始化提示框
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    //按钮：从相册选择，类型：UIAlertActionStyleDefault
    [alert addAction:[UIAlertAction actionWithTitle: Localized(@"public_album") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [GGPermissionsManage checkPhotosOpenPer:^{
            //初始化UIImagePickerController
            UIImagePickerController *PickerImage = [[UIImagePickerController alloc]init];
            //获取方式1：通过相册（呈现全部相册），UIImagePickerControllerSourceTypePhotoLibrary
            //获取方式2，通过相机，UIImagePickerControllerSourceTypeCamera
            //获取方法3，通过相册（呈现全部图片），UIImagePickerControllerSourceTypeSavedPhotosAlbum
            PickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            //允许编辑，即放大裁剪
            PickerImage.allowsEditing = YES;
            //自代理
            PickerImage.delegate = self;
            PickerImage.modalPresentationStyle = UIModalPresentationFullScreen;
            //页面跳转
            [self presentViewController:PickerImage animated:YES completion:nil];
        } faile:^{
            
        }];
        
    }]];
    //按钮：拍照，类型：UIAlertActionStyleDefault
    [alert addAction:[UIAlertAction actionWithTitle: Localized(@"public_camera") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
        /**
         其实和从相册选择一样，只是获取方式不同，前面是通过相册，而现在，我们要通过相机的方式
         */
        [GGPermissionsManage checkCameraPer:^{
            UIImagePickerController *PickerImage = [[UIImagePickerController alloc]init];
            //获取方式:通过相机
            PickerImage.sourceType = UIImagePickerControllerSourceTypeCamera;
            PickerImage.allowsEditing = YES;
            PickerImage.delegate = self;
            PickerImage.modalPresentationStyle = UIModalPresentationFullScreen;
            [self presentViewController:PickerImage animated:YES completion:nil];
        } faile:^{
            
        }];
        
    }]];
    //按钮：取消，类型：UIAlertActionStyleCancel
    [alert addAction:[UIAlertAction actionWithTitle: Localized(@"public_cancel") style:UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
}

- (BOOL)isSingle {
    
    
    return self.vcType == Report_Swap || self.vcType == Report_FAQ || self.vcType == Report_buyPB;
}

#pragma mark - TextView delegate --
- (void)textViewDidChange:(UITextView *)textView {
    
    _inPutNumL.text = [NSString stringWithFormat:@"%ld/300",textView.text.length];
    
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    
    if ([string isEqualToString:@""]) {
        return YES;
    }
//    if (textField.text.length >= 20) {
//        return NO;
//    }
    
    return [BRTools canInputText:string hasEmail:self.vcType == Report_FAQ];
}

#pragma mark - UINavigationControllerDelegate, UIImagePickerControllerDelegate
//PickerImage完成后的代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    //定义一个newPhoto，用来存放我们选择的图片。
    UIImage *newPhoto = [info objectForKey:@"UIImagePickerControllerEditedImage"];
    // 压缩需要上传的图片
    UIImage *uploadImage = [self imageWithImageSimple:newPhoto scaledToSize:newPhoto.size];
    CGFloat scale = 1;
    if (uploadImage.size.width > 800) {
        scale = 0.5;
    }
    NSData *uploadData = UIImageJPEGRepresentation(uploadImage, scale);;
    [self uploadHeader: uploadData];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)uploadHeader:(NSData*)data{
    
    [BRHud showHud];
    WS(weakSelf);
    [BRAPI uploadFiles:data beginBlock:^{

    } successBlock:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        [BRHud hidden];
        
        NSInteger code = [responseObject[@"code"] integerValue];
        if (code != 0) {
            NSLog(@"%@",responseObject[@"message"])
            
            return;
        }
        
        [self->_imgArrs addObject:responseObject[@"data"][@"value"]];
        [weakSelf resetImagesView];

        

    } failureBlock:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [BRHud hidden];
    }];
    
    
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}
//压缩图片
- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
{
    // Create a graphics image context
    UIGraphicsBeginImageContext(newSize);
    // Tell the old image to draw in this new context, with the desired
    // new size
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    // End the context
    UIGraphicsEndImageContext();
    // Return the new image.
    return newImage;
}

#pragma mark - SET UI --
- (void)setUI {
    
    NSString *titleStr = Localized(@"home_reportFaultPB");
    NSString *text = Localized(@"home_select");
    NSString *textFStr = Localized(@"home_stationID");
    NSString *textVStr = Localized(@"home_describeIssueText");
    if (self.vcType == Report_FAQ || self.vcType == Report_Swap || self.vcType == Report_buyPB) {
        titleStr = Localized(@"help_fb");
        text = Localized(@"help_category");
        textFStr = Localized(@"help_enterEmail");
        textVStr = Localized(@"help_inputFBContent");
    }
    if (self.vcType == Report_NoInset) {
        text = Localized(@"home_unfotunatelyText");
        titleStr = Localized(@"home_reportIssue");
    }
   
    [self br_createTop:titleStr];
    
    
    UIView *submitView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - (kSafeAreaBottomHeight + 82), kScreenWidth, (kSafeAreaBottomHeight + 82) )];
    submitView.backgroundColor = UIColor.clearColor;
    [self.view addSubview:submitView];
    [submitView br_addBaseShadow];
    
    QMUIButton *submitBtn = [BRToolsView br_btnBGImg:Localized(@"home_submit")];
    
    [submitView addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(52);
        make.width.mas_equalTo(kScreenWidth - 28);
        make.centerX.equalTo(self.view);
        make.top.equalTo(submitView.mas_top).offset(14);
    }];
    [submitBtn addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];

    UIScrollView *scrollView = [[UIScrollView alloc] init];
    [self.view addSubview:scrollView];
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.offset(kSafeAreaTopHeight);
        make.bottom.offset(-(kSafeAreaBottomHeight  + 82));
    }];
    
    UIView *contentView = [[UIView alloc] init];
    contentView.userInteractionEnabled = YES;
    [scrollView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(scrollView);
        make.left.offset(20);
        make.right.offset(-20);
        make.width.mas_equalTo(kScreenWidth - 40);
    }];
    
    QMUILabel *titleL = [[QMUILabel alloc] init];
    titleL.textAlignment = NSTextAlignmentLeft;
    titleL.textColor = kColorTitle;
    titleL.text = text;
    titleL.numberOfLines = 0;
    titleL.font = [UIFont fontB:17];
    [contentView addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(contentView).offset(10);
        make.right.equalTo(contentView);
        make.top.equalTo(contentView).offset(14);
    }];
    
    NSInteger lineN  = ceilf(self.faults.count / 2.0);
    UIView *faultView = [[UIView alloc] init];
    faultView.userInteractionEnabled = YES;
    faultView.hidden = (self.vcType == Report_NoInset);
    [contentView addSubview:faultView];
    
    BOOL isSingle = self.isSingle;
    //优化德语展示
    NSString *la = [BRLanguageManager share].language;
    BOOL isDE = [la isEqualToString:@"de"] && !isSingle;
    
    _faultView = faultView;
    CGFloat item_w = (kScreenWidth - 50) /  2.0;
    for (int i = 0; i < lineN; i++) {
        for (int y = 0; y < 2; y++) {
            
            int index = i  * 2 + y;
            if (index == self.faults.count) break;
            BRFaultItemView *faultItem = [[BRFaultItemView alloc] init];
            faultItem.text = self.faults[index];
            [faultView addSubview:faultItem];
            faultItem.userInteractionEnabled = YES;
            faultItem.tag = 100 + index;
            faultItem.isSingle = isSingle;
            faultItem.isSelected = NO;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(faultClick:)];
            [faultItem addGestureRecognizer:tap];
            
            CGFloat h = 48;
            CGFloat top = 58;
            if (i == 1 && isDE) {
                h = 60;
                faultItem.numOfLine = 3;
            }
            if (i == 2 && isDE)  top = 64; // 12 / i
            
            [faultItem mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(item_w);
                make.height.mas_equalTo(h);
                make.left.offset((item_w + 10) * y);
                make.top.offset(top * i);
                if (index == self.faults.count - 1) {
                    make.bottom.offset(-10);
                }
                
            }];
            
          
        }
        
    }
    [faultView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleL.mas_bottom).offset(14);
        make.left.right.equalTo(contentView);

    }];
    // 28  [14 + 12 + 44 * 3]
//    CGFloat idTF_Y  =  self.vcType == Report_NoInset ? 28 : (26 + 44 * lineN);
    CGFloat clearR  =  self.vcType == Report_FAQ ? 20 : 80;
    CGFloat clearR2  =  self.vcType == Report_FAQ ? 20 : 70;
    QMUITextField *enterIDTf = [[QMUITextField alloc] init];
    enterIDTf.clearButtonMode = UITextFieldViewModeWhileEditing;
    enterIDTf.clearButtonPositionAdjustment = UIOffsetMake(-clearR2, 0);
    enterIDTf.textInsets = UIEdgeInsetsMake(0, 16, 0, clearR);
    enterIDTf.placeholder = textFStr;
    enterIDTf.font = [UIFont fontM:14];
    enterIDTf.placeholderColor = kColorTitleAAC;
    [contentView addSubview:enterIDTf];
    enterIDTf.layer.cornerRadius = 7;
    enterIDTf.delegate = self;
    enterIDTf.tintColor = kColorMain;
    enterIDTf.backgroundColor = kColorBGEC;
    [enterIDTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(kScreenWidth - 40);
        make.height.mas_equalTo(60);
        make.centerX.equalTo(contentView);
        if (self.vcType == Report_NoInset) {
            make.top.equalTo(titleL.mas_bottom).offset(28);
        }else {
            make.top.equalTo(faultView.mas_bottom).offset(12);
        }
        
    }];
    _numTextF = enterIDTf;
    enterIDTf.maximumTextLength = self.vcType == Report_FAQ ? 150 : 20;
    
    QMUIButton *cameraBtn = [[QMUIButton alloc] init];
    [cameraBtn setBackgroundImage:UIImageMake(@"faq_camera") forState:UIControlStateNormal];
    [cameraBtn setBackgroundColor:UIColorClear];
    cameraBtn.titleLabel.font = [UIFont br_fontM:12];
    [enterIDTf addSubview:cameraBtn];
    [cameraBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(enterIDTf);
        make.right.equalTo(enterIDTf).offset(-8);
        make.height.mas_equalTo(44);
        make.width.mas_equalTo(44);
    }];
    [cameraBtn addTarget:self action:@selector(openCameraClick:) forControlEvents:UIControlEventTouchUpInside];
    cameraBtn.hidden = isSingle; // 这2类型不需要扫码输入机柜
    
    UIView *bottomView = [[UIView alloc] init];
    bottomView.userInteractionEnabled = YES;
    bottomView.backgroundColor = kColorBGEC;
    bottomView.layer.cornerRadius = 7;
    bottomView.layer.masksToBounds = YES;
    [contentView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(enterIDTf.mas_bottom).offset(12);
        make.left.right.equalTo(contentView);
        make.height.mas_equalTo(300);
        make.bottom.equalTo(contentView.mas_bottom).offset(-20);
    }];
    
    QMUITextView *describeView = [[QMUITextView alloc] init];
    describeView.placeholder = textVStr;
    describeView.placeholderColor = kColorTitleAAC;
    describeView.font = [UIFont br_fontM:14];
    describeView.maximumTextLength = 300;
    describeView.backgroundColor = UIColorClear;
    describeView.delegate = self;
    describeView.tintColor = kColorMain;
    [bottomView addSubview:describeView];
    [describeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(16);
        make.left.offset(16);
        make.right.offset(-16);
        make.height.mas_equalTo(160);
    }];
    _textView = describeView;
    
    QMUILabel *numLB = [[QMUILabel alloc] init];
    numLB.textAlignment = NSTextAlignmentRight;
    numLB.textColor = kColorTitleAAC;
    numLB.text = @"0/300";
    numLB.font = [UIFont br_fontM:12];
    [bottomView addSubview:numLB];
    [numLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bottomView).offset(-16);
        make.top.equalTo(describeView.mas_bottom).offset(0);
    }];
    _inPutNumL = numLB;
    
//    UIView *stackView = [[UIView alloc] init];
//    stackView.backgroundColor = UIColorClear;
    UIStackView *stackView = [[UIStackView alloc] init];
    stackView.spacing = 16;
    [bottomView addSubview:stackView];
    [stackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomView.mas_left).offset(16);
        make.height.mas_equalTo(72);
//        make.width.mas_equalTo(248);
        make.top.equalTo(describeView.mas_bottom).offset(36);
    }];
    _stackView  = stackView;
    for (int i = 0; i < 4; i++) {
        QMUIButton *btn = [[QMUIButton alloc] initWithFrame:CGRectMake(0, 0, 72, 72)];
        [btn setBackgroundImage:UIImageMake(@"faq_imgDefault") forState:UIControlStateNormal];
        btn.layer.cornerRadius = 5;
        btn.layer.masksToBounds = YES;
        [stackView addArrangedSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.width.mas_equalTo(72);
        }];
        if (i != 3) {
            btn.hidden =  YES;
        }
        btn.tag = 200 + i;
        [btn addTarget:self action:@selector(imgTouch:) forControlEvents:UIControlEventTouchUpInside];
        if (i < 3) {
            UIImageView *delImg = [[UIImageView alloc] initWithImage:UIImageMake(@"info_imgDele")];
            [btn addSubview:delImg];
            [delImg mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(2);
                make.right.offset(-2);
                make.height.width.mas_equalTo(16);
            }];
            
        }
    }
    {
        QMUILabel *numLB = [[QMUILabel alloc] init];
        numLB.textAlignment = NSTextAlignmentRight;
        numLB.textColor = kColorTitleAAC;
        numLB.text = @"0/3";
        numLB.font = [UIFont br_fontM:12];
        [bottomView addSubview:numLB];
        [numLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(stackView);
            make.right.equalTo(bottomView.mas_right).offset(-16);
        }];
        _imgNumL = numLB;
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
